#include <vector>

using namespace std;

class Solution {
public:
    vector<int> twoSum(vector<int>& nums, int target) 
    {
        vector<int> ret;
        int begin = 0, end = nums.size() - 1;
        while (begin < end)
        {
            if (nums[begin] + nums[end] <target)
            {
                ++begin;
            }
            else if (nums[begin] + nums[end] > target)
            {
                --end;
            }
            else 
            {
                ret.push_back(nums[begin]);
                ret.push_back(nums[end]);
                break;
            }
        }
        return ret;
    }
};